package com.squirrel.common.util;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 配置信息的实体类，获取JWT配置
 *
 * 远键：
 * 不知道这个Audience具体有什么作用，鉴于代码全部使用的是同一个Audience（属性值相同），
 * 故使用单例模式
 *
 * @author olay
 * @version 1.0
 * @date 6/3/2021 10:55 PM
 */
@Data
//@ConfigurationProperties(prefix = "audience")
//@Component
@Accessors(chain = true)
public class Audience {
    private String clientId;
    private String base64Secret;
    private String name;
    private int expiresSecond;

    // add by yuanjian 2021/12/15
    private volatile static Audience instance;

    private Audience() { }

    public static Audience getInstance() {
        if (null == instance) {
            synchronized (Audience.class) {
                if (null == instance) {
                    instance = new Audience().setClientId("clientId")
                            .setBase64Secret("MDk4ZjZiY2Q0ZDM3M2gzMjYyN2ZjYDSOIUOIEWQEQWEQWDASDSAEQWE=")
                            .setName("restapiuser")
                            .setExpiresSecond(172800);
                }
            }
        }
        return instance;
    }

    // add by yuanjian 2021/12/13
    @Deprecated
    public static Audience getDefaultAudience() {
        return new Audience().setClientId("clientId")
                .setBase64Secret("MDk4ZjZiY2Q0ZDM3M2gzMjYyN2ZjYDSOIUOIEWQEQWEQWDASDSAEQWE=")
                .setName("restapiuser")
                .setExpiresSecond(172800);
    }
}
